Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(flags): Fire callback when decide errors out #1056

Merged
merged 3 commits into from
Mar 7, 2024

Conversation

neilkakkar
Copy link
Collaborator

Changes

Fire callbacks with error param so we don't block clients waiting for flags to load.

Noticed this isn't present on the first Decide response, will add it there too.
...

Checklist

  • Tests for new code (see advice on the tests we use)
  • Accounted for the impact of any changes across different browsers
  • Accounted for backwards compatibility of any changes (no breaking changes in posthog-js!)

@neilkakkar neilkakkar requested a review from benjackwhite March 7, 2024 13:22
Copy link

github-actions bot commented Mar 7, 2024

Size Change: +344 B (0%)

Total Size: 852 kB

Filename Size Change
dist/array.full.js 182 kB +86 B (0%)
dist/array.js 124 kB +86 B (0%)
dist/es.js 124 kB +86 B (0%)
dist/module.js 124 kB +86 B (0%)
ℹ️ View Unchanged
Filename Size
dist/exception-autocapture.js 12.1 kB
dist/recorder-v2.js 106 kB
dist/recorder.js 58.7 kB
dist/surveys-module-previews.js 62.1 kB
dist/surveys.js 58.4 kB

compressed-size-action

}
// :TRICKY: We want to fire the callback even if the request fails
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This feels like a hack... Why call receivedFeatureFlags when from what I can see the only thing it needs is this._fireFeatureFlagsCallbacks(errorsLoading) - why not just call that directly?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I also want all the other stuff that this function does (like setting decideEndpointWasHit) which then warns users when they call getFeatureFlag() that flags didn't load in time.

const { flags, flagVariants } = this._prepareFeatureFlagsForCallbacks()
this.featureFlagEventHandlers.forEach((handler) => handler(flags, flagVariants))
this.featureFlagEventHandlers.forEach((handler) => handler(flags, flagVariants, errorsLoading))
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I really have a pet peeve for functions that just have a bunch of arguments that can be true or 1 or something.

Feels like this is meta info - why not turn it into an object like context: { errors: true } so that it would be easy to extend further in the future.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Very reasonable, will do 👍

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Makes sense for the public interface to have a context object, but keeping interals as a param. Don't see any need to convert yet, and easy to refactor when/if we have more params to these internal funcs

@neilkakkar neilkakkar requested a review from benjackwhite March 7, 2024 13:44
@neilkakkar neilkakkar marked this pull request as ready for review March 7, 2024 13:49
@neilkakkar
Copy link
Collaborator Author

Merging into yours 👍

@neilkakkar neilkakkar merged commit 1925d7d into feat/request-refactor Mar 7, 2024
11 checks passed
@neilkakkar neilkakkar deleted the flag-receiver branch March 7, 2024 16:30
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants